# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer: Johannes Heimansberg <git@jhe.dedyn.io>
pkgname=domoticz
pkgver=2022.1
pkgrel=3
pkgdesc="Open source Home Automation System"
url="https://www.domoticz.com/"
arch="all"
license="GPL-3.0-or-later"
options="!check" # missing pytest_bdd module
pkgusers="$pkgname"
pkggroups="$pkgname"
makedepends="cmake openssl1.1-compat-dev zlib-dev curl-dev boost-dev sqlite-dev
	lua5.3-dev mosquitto-dev libusb-compat-dev openzwave-dev python3-dev
	minizip-dev jsoncpp-dev cereal samurai
	"
checkdepends="py3-pytest"
subpackages="$pkgname-openrc"
install="$pkgname.pre-install"
source="domoticz-$pkgver.tar.gz::https://github.com/domoticz/domoticz/archive/$pkgver.tar.gz
	domoticz.confd
	domoticz.initd
	luafix.patch
	domoticz-python-3.10.patch
	"
build() {
	cmake -B build -G Ninja \
		-DBUILD_SHARED_LIBS=True \
		-DUSE_STATIC_LIBSTDCXX=OFF \
		-DUSE_STATIC_OPENZWAVE=OFF \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/var/lib/domoticz \
		-DUSE_BUILTIN_MQTT=OFF \
		-DUSE_BUILTIN_SQLITE=OFF \
		-DUSE_BUILTIN_MINIZIP=OFF \
		-DUSE_BUILTIN_JSONCPP=OFF \
		-DUSE_STATIC_BOOST=NO \
		-DUSE_STATIC_LIBSTDCXX=NO \
		-DUSE_STATIC_OPENZWAVE=NO \
		-DUSE_LUA_STATIC=NO \
		-DUSE_OPENSSL_STATIC=NO
	cmake --build build
}

check() {
	pytest -rA --tb=no test/gherkin/
}

package() {
	DESTDIR="$pkgdir" cmake --build build --target install

	mkdir -p "$pkgdir"/usr/bin \
		"$pkgdir"/usr/share/$pkgname
	mv "$pkgdir"/var/lib/domoticz/domoticz \
		"$pkgdir"/usr/bin/
	mv "$pkgdir"/var/lib/domoticz/www \
		"$pkgdir"/usr/share/$pkgname/
	mv "$pkgdir"/var/lib/domoticz/Config \
		"$pkgdir"/usr/share/$pkgname/
	rm -f "$pkgdir"/var/lib/domoticz/updatedomo

	chown -R $pkgname "$pkgdir"/var/lib/domoticz

	install -D -m755 "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
	install -D -m644 "$srcdir"/$pkgname.confd \
		"$pkgdir"/etc/conf.d/$pkgname
}

sha512sums="
d75ce3c0033321c20de67bb1e69e33df03f488ca7974bcbecbb109a7c516d19885dc24c6edaa664df51798692c7bff4e3967a0382b6c1a093e4133283a747e86  domoticz-2022.1.tar.gz
724440da335f1e22c8dc181df62dac9ad2bcca98b39bff059de4be5901a93a0a8cb6864d92262092041d796ee7d3933f62cf337316d35a800bbb44f84a1709e0  domoticz.confd
aee1461afa96b6c9af6b88450a2e179990aca8ab74974b03242f58f786843f121fa1dec1177e82c143a775ad2e3db8603f54f341614e9fd55f645085c370b54d  domoticz.initd
83e568a2e5e310ffd22c8e8546f96ee15824817a6a65d6027195689a8a7668ec54107c68d54b70cc998cbef36a2b976c9636080ab94e91462b2280de0ac12058  luafix.patch
6b4e1ccd9ba9065cac74ecf469073bcd68d22a98cc6fd86e29ec078355bbc142e1b928bf62f9eced58256a6ae0a5be5de5e54fa8114ff4aa01c97a65a2ba809a  domoticz-python-3.10.patch
"
